/*
Copyright (C) 2006 Team Blur.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/


#ifndef __SG_PUBLIC_H__
#define __SG_PUBLIC_H__


#define SGAME_API_VERSION		2

// Functions exported by the game library
typedef struct {
	int						apiVersion;

	int						gameProtocol;

	// Connects a client to the game.
	// Returns NULL if the client is allowed to connect, otherwise returns a
	// string with the reason for denial.
	const char *			(*ClientConnect)(int clientNum, bool firstTime, const char *ip, char *userInfo);

	// Disconnects a client from the game
	void					(*ClientDisconnect)(int clientNum);

	// Called when the user info for a client has been changed.
	// The user info string can be modified by the game.
	void					(*ClientUserInfoChanged)(int clientNum, char *userInfo);

	// Spawns the player entity for a client
	void					(*ClientBegin)(int clientNum);

	// Executes a string command for a client.
	// The string has been tokenized by the engine and the Cmd_* functions can
	// be used to retrieve the command arguments.
	void					(*ClientCommand)(int clientNum);

	// Executes the user command for a client
	void					(*ClientThink)(int clientNum, const userCmd_t *userCmd);

	// Writes a game state for a client, starting at the given offset. A game
	// state usually contains things such as config strings and entity
	// baselines.
	// This is only called during the client connection process, before it is
	// allowed to the enter the game.
	void					(*ClientWriteGameState)(int clientNum, ByteBuffer *msg);

	// Writes a snapshot for a client
	void					(*ClientWriteSnapshot)(int clientNum, ByteBuffer *msg);

	// Writes a string with the current status of a client. This will be things
	// like name, team, ping, score, etc.
	// Returns the string length, or -1 if it was overflowed.
	//int						(*ClientGetStatus)(int clientNum, char *status, int size);
	// Runs a game frame
	void					(*RunFrame)(int time);

	// Loads the level and spawns all the entities
	void					(*SpawnEntities)(const char *levelName, int levelTime);

	// Sets up baselines for more efficient communications. The baselines will
	// be transmitted to all clients when they ask for a game state.
	// This is only called during server initialization, after SpawnEntities.
	void					(*SetupBaselines)(void);

	// Initializes the game
	void					(*Init)(void);

	// Shuts down the game
	void					(*Shutdown)(void);
} sgExport_t;

// Functions imported from the engine
typedef struct {
	odMemory_t				odMemory;
	odFileSystem_t			odFileSystem;
	odCmdSystem_t			odCmdSystem;
	odCVarSystem_t			odCVarSystem;
	odParser_t				odParser;
	odSystem_t				odSystem;
	odCollision_t			odCollision;
	odEditor_t				odEditor;

	// Sends a reliable command to the given client
	void					(*AddReliableCommand)(int clientNum, const char *fmt, ...);

	// Broadcasts a reliable command to all clients
	void					(*BroadcastReliableCommand)(const char *fmt, ...);

	// Drops the connection of the given client
	void					(*DropClient)(int clientNum, const char *reason);
} sgImport_t;

// Game API prototype
typedef sgExport_t *		(*GETSGAMEAPI)(sgImport_t *);


#endif	// __SG_PUBLIC_H__
